<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>vue 懒加载插件</title>
  <script type="text/javascript" src="./node_modules/vue/dist/vue.min.js"></script>
  <!-- <script type="text/javascript" src="node_modules/vue-lazyload/vue-lazyload.js"></script> -->
  <script type="text/javascript" src="./vue-lazyload.js"></script>
  <script type="text/javascript" src="./node_modules/axios/dist/axios.js"></script>
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      list-style: none;
    }
    #app {
      padding-left: 50px;
    }
    .scroll-box {
      width: 300px;
      height: 500px;
      border: 1px solid #000;
      overflow-y: auto;
    }
    img {
      width:  150px;
      height: 150px;
      vertical-align: top;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="scroll-box">
      <ul class="list">
        <li v-for="(img, index) of imgs" :key="img">
          <img v-lazy="img" alt="" />
        </li>
      </ul>
    </div>
  </div>
  <script type="text/javascript">
    Vue.use(VueLazyload, {
      preLoad: 1.3,
      error: '',
      loading: './img/loading.gif',
      attempt: 1
    })
    let vm = new Vue({
      el: '#app',
      data() {
        return {
          imgs: []
        }
      },
      created() {
        axios.get('http://127.0.0.1:9000/imgs').then(res => {
          this.imgs = res.data.data;
        })
      }
    })
  </script>
</body>
</html>